<?php
//添加记录
function insertData($table,$arrValue){
	foreach($arrValue as $key=>$value){
		$keyName .= '`'.$key."`,";
		$keyValue .= "'".$value."',";
	}
	$keyName = substr($keyName,0,strlen($keyName)-1);
	$keyValue = substr($keyValue,0,strlen($keyValue)-1);
	$sql = "INSERT INTO `".$table."` (".$keyName.") VALUES (".$keyValue.")";
	//echo $sql;
	//mysql_query($sql);
	//return $sql;
	if(mysql_query($sql)) return true;
}
//删除记录
function deleteData($table,$where){
	$sql = "DELETE FROM `".$table."` WHERE ".$where;
	mysql_query($sql);
}
//修改记录 dataUpdate('table',array(key=>'val',key=>'val'),'key = val') 或者  updateData('table','key = val','key = val')
function updateData($table,$value,$where=null){
	$value = sqlValue($value);
	$where = $where;
	$sql = "UPDATE `$table` SET $value WHERE $where";
	mysql_query($sql);
}
//查询记录
function selectData($query,$table,$where=null,$order=null,$limit=null){ 
	$sql .= "SELECT ".$query." FROM `".$table."`";
	if($where) $sql .= " WHERE ".$where;
	if($order) $sql .= " ORDER BY ".$order;
	if($limit) $sql .= " LIMIT ".$limit;
	return mysql_query($sql);
}
function sqlValue($value){
	if(is_array($value)){
		$i=0;
		$t = '';
		foreach ($value as $k => $v){
			$t .= "`$k` = '$v'";
			$i++;
			if($i<count($value) ) $t .=',';
		}
		$value = $t;
	}else{
		$t = explode('=',$value);
		$k = $t[0];
		$v = $t[1];
		$value = "`".$k."` = '".$v."'";
	}
	return $value;
}
?>